package com.seari.groovyrunner.utils;

import java.io.*;

public class FileUtil {
    public static String readFile(File file) throws IOException {
        BufferedReader reader = null;
        StringBuffer sbf = new StringBuffer();
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                sbf.append(tempStr);
                sbf.append("\r\n");
            }
        }finally {
            if (reader != null) {
                reader.close();
            }
        }
        return sbf.toString();
    }
    public static boolean saveFile(String path,String code) throws IOException {
        File file = new File(path);
        if (!file.exists()){
            FileWriter writer=new FileWriter(file);
            writer.write(code);
            writer.close();
            return true;
        }
        return false;
    }
}
